package leetcode.tree.binary.traversal;

import leetcode.tree.binary.TreeNode;

/**
 * 100. 相同的树
 */
public class SameTree {


    /**
     * 递归实现相同树的比较
     *
     * @param p     树1
     * @param q     树2
     * @return
     */
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        } else if (p == null || q == null) {
            return false;
        } else if (p.val != q.val) {
            return false;
        } else {
            return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        }
    }
}
